package com.mall.b2c.domain.goods;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;

import com.mall.common.domain.BaseEntity;

@Entity
@Table(name = "b2c_goods_tag")
public class GoodsTagDomain extends BaseEntity {
	private static final long serialVersionUID = -2073189311081322356L;
	
	private Integer priority;
	private GoodsDomain goods;
	private TagDomain tag;

	@PrePersist
	public void prePersist() {
		if(this.getPriority() == null) {
			this.setPriority(10);
		}
	}
	
	@PreUpdate
	public void preUpdate() {
		if(this.getPriority() == null) {
			this.setPriority(10);
		}
	}
	
	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "goods_id")
	public GoodsDomain getGoods() {
		return goods;
	}

	public void setGoods(GoodsDomain goods) {
		this.goods = goods;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "tag_id")
	public TagDomain getTag() {
		return tag;
	}

	public void setTag(TagDomain tag) {
		this.tag = tag;
	}

}
